/*
Copyright 2011 Christian Dadswell
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package uk.co.chrisdadswell.bbcbc;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class Activity_Britify extends ListActivity {

	final static String APP_TAG = "BBCBC";
	final static String ACT_TAG = "Activity_Britify: ";
	static String selectedStation = null;
	static String stationShortName = null;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
	  super.onCreate(savedInstanceState);
	  setContentView(R.layout.lists);
	  Log.d(APP_TAG, ACT_TAG + "... OnCreate ...");
	  
	  // SETUP VIEW
	  TextView wTitle = (TextView) findViewById(R.id.tv_Title);
	  wTitle.setText("Select an option to view Britify playlists");

      String[] Britify_Stations = {"Radio 1","Radio 2","Radio 3","Radio 4","6 Music","1Xtra","Desert Island Discs"};
      
	  setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, Britify_Stations));
	  getListView().setTextFilterEnabled(true);
	  getListView().setSmoothScrollbarEnabled(true);
	  getListView().setFadingEdgeLength(60);
	  getListView().setFastScrollEnabled(true);
	  getListView().setVerticalFadingEdgeEnabled(true);
	}	
	
	@Override
	protected void onListItemClick(ListView listView, View view, int position, long id) {
	    super.onListItemClick(listView, view, position, id);
		Intent intentWebView = new Intent();
	    Object pos = this.getListAdapter().getItem(position); 
	    selectedStation = pos.toString();

	    //GET THE SELECTED STATION SHORT NAME
        if(selectedStation == "Radio 1") {
        	stationShortName = "radio1";
        }else if(selectedStation == "Radio 2"){
            stationShortName = "radio2";
        }else if(selectedStation == "Radio 3"){
            stationShortName = "radio3";        	
        }else if(selectedStation == "Radio 4"){
            stationShortName = "radio4";        	
        }else if(selectedStation == "6 Music"){
            stationShortName = "6music";
        }else if(selectedStation == "1Xtra"){
            stationShortName = "1xtra";        	
        }else if(selectedStation == "Desert Island Discs"){
            stationShortName = "did";        	
        }
        
        Log.d(APP_TAG, ACT_TAG + "ONCREATE: " + stationShortName);
        
		intentWebView.setClass(Activity_Britify.this, Activity_BritifyWebView.class);
		intentWebView.putExtra("StationShortName", stationShortName);
	    startActivity(intentWebView);
	}

	// PREPARE OPTIONS MENU
	public boolean onPrepareOptionsMenu(Menu menu) {
		menu.clear();
		menu.add(0,Constants.MENU_PREFERENCES,0,"Help / Support").setIcon(R.drawable.preferences);
		//TODO: ADD MENU TO CHANGE REGION
		return super.onPrepareOptionsMenu(menu);
	}
		
	@Override
	public boolean onOptionsItemSelected (MenuItem item){
		switch (item.getItemId()){
		case Constants.MENU_PREFERENCES:
			Intent prefsActivity = new Intent(Activity_Britify.this, Activity_Preferences.class);
			startActivity(prefsActivity);
			break;
		}
		return false;
	}
}